package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.计数;

import java.util.Arrays;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/14 22:24
 */
public class 道路的最大总重要性 {
    //https://leetcode.cn/problems/maximum-total-importance-of-roads/
    //大致思路 点出现的次数越多定义数值越大
    public long maximumImportance(int n, int[][] roads) {
        int[] nums = new int[n];
        for (int[] road : roads) {
            nums[road[0]]++;
            nums[road[1]]++;
        }
        Arrays.sort(nums);
        long res = 0;
        for (int i = 0; i < nums.length; i++) {
            res += (long) nums[i] * (i + 1);
        }
        return res;

    }
}
